import React,{Component} from 'react'
import { Table } from 'antd';

class MyTable extends Component{
    constructor(props){
        super(props)
        this.state ={
            columns:this.props.columns,
            data:this.props.data,
            title:this.props.title,
            selectRowIndex:''
        }
    }
    componentWillReceiveProps(nextProps){
        if(nextProps != this.props){
            this.setState({
                columns:nextProps.columns,
                data:nextProps.data,
                title:nextProps.title
            })
        }
    }
    handleClickRow (record, index, event){
        this.setState({
            selectRowIndex:index
        })
    }
    render(){
        return (
            <Table
                onRowClick={this.handleClickRow.bind(this)}
                rowClassName={(record, index) =>{
                    if(index === this.state.selectRowIndex){
                        return "reds"
                    }
                    return ''
                }}
                pagination={false}
                showHeader={false}
                columns={this.state.columns}
                dataSource={this.state.data}
                bordered
                title={() => this.state.title}
          />
        )
    }
}

export default MyTable